package com.gg.fmallspringboot.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 作者:Miki
 * 时间:2021/6/19 12:44
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result<T> {

    private Integer code;//状态码code，小于0表示错误，大于0表示正确
    private String msg;
    private T data;


    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 常用的成功的 Result
    public static Result buildSuccess(Object data, Integer code) {
        return new ResultBuilder().code(1).msg("success").data(data).build();
    }

    // 常用的失败的 Result
    public static Result buildFail(String msg, Integer code) {
        return new ResultBuilder().code(-1).msg(msg).build();
    }


}
